<!--
 * @Description: 招聘企业详情列表
 * @Author: liyujie
 * @Date: 2021/09/22
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/09/22
-->
<template>
    <PageLayout
        title="职位详情"
        class="page-layout-recruit-company-detail"
    >
        <template slot="sub-title">
            公司名称：{{ company_name }}
        </template>
        <template slot="header-right">
            <div
                class="back"
                @click="handleRoute('recruitCompanyList')"
            >
                返回
            </div>
        </template>
        <!-- 筛选-->
        <template slot="filter">
            <div class="filter-item">
                <div class="filter-item__title">
                    职位名称
                </div>
                <el-input
                    placeholder="职位名称"
                    v-model="filterData.keyword"
                    suffix-icon="el-icon-search"
                    clearable
                    size="medium"
                    @keydown.enter.native="getTableData(1)"
                />
            </div>
            <div class="filter-item">
                <div class="filter-item__title">
                    状态
                </div>
                <el-select
                    v-model="filterData.status"
                    filterable
                    size="medium"
                    @change="getTableData(1)"
                >
                    <el-option
                        label="全部"
                        :value="99"
                    />
                    <el-option
                        label="招聘中"
                        :value="1"
                    />
                    <el-option
                        label="已关闭"
                        :value="0"
                    />
                </el-select>
            </div>
            <div class="filter-item">
                <div class="filter-item__title">
                    招聘类型
                </div>
                <el-select
                    v-model="filterData.type"
                    filterable
                    size="medium"
                    @change="getTableData(1)"
                >
                    <el-option
                        label="全部"
                        :value="99"
                    />
                    <el-option
                        label="实习生"
                        :value="1"
                    />
                    <el-option
                        label="毕业校招"
                        :value="2"
                    />
                </el-select>
            </div>
            <div class="filter-item">
                <el-button
                    type="primary"
                    size="small"
                    class="query-button"
                    @click="getTableData(1)"
                >
                    查询
                </el-button>
            </div>
        </template>
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            ref="tempLateName"
            class="data-table"
            v-loading="tableLoading"
        >
            <el-table-column
                label="序号"
                align="center"
                width="80"
                type="index"
            />
            <el-table-column
                prop="company_name"
                label="招聘类型"
                show-overflow-tooltip
                align="left"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.type === 1">实习生</span>
                    <span v-if="scope.row.type === 2">毕业校招</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="position_name"
                label="职位类别"
                align="center"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="title"
                label="职位名称"
                align="center"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                label="工作地点"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    {{ scope.row.address_province_name }}
                    {{ scope.row.address_city_name }}
                    {{ scope.row.address_county_name }}
                </template>
            </el-table-column>
            <el-table-column
                label="薪资范围"
                align="left"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <div v-if="scope.row.money_time_type === 1">
                        {{ scope.row.money_min }} - {{ scope.row.money_max }} 元/日
                    </div>
                    <div v-if="scope.row.money_time_type === 2">
                        {{ scope.row.money_min / 1000 }} - {{ scope.row.money_max / 1000 }} K/月
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="学历要求"
                align="left"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    {{ scope.row.education_level | levelFilter }}
                </template>
            </el-table-column>
            <el-table-column
                label="最近一次发布时间"
                align="left"
                :formatter="emptyFormatter"
                width="160"
            >
                <template slot-scope="scope">
                    {{ scope.row.last_submit_time * 1000 | dateFormatter('yyyy-MM-dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                label="状态"
                align="center"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <div class="status-wrapper">
                        <div
                            class="status-dot"
                            :class="['status-dot', scope.row.status === 1 ? 'success' : 'danger']"
                        />
                        <div>{{ scope.row.status | statusFilter }}</div>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="left"
                width="120"
            >
                <template slot-scope="scope">
                    <div class="option-btn-group">
                        <el-button
                            type="text"
                            size="medium"
                            @click="beforeSetStatus(scope.row)"
                        >
                            {{ scope.row.status ? '关闭招聘' : '开放招聘' }}
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <template slot="pagination">
            <div/>
            <el-pagination
                layout="total, prev, pager, next, jumper"
                background
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </template>
    </PageLayout>
</template>

<script>
import {back} from '@/mixin/back';

export default {
    name: 'RecruitCompanyDetail',
    mixins: [back],
    components: {},
    data() {
        return {
            company_name: '',
            filterData: {
                hire_no: '',
                keyword: '',
                status: 99,
                type: 99
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            authResult: {}
        };
    },
    computed: {},
    watch: {},
    filters: {
        statusFilter(val) {
            switch (val) {
                case 0:
                    return '已关闭';
                case 1:
                    return '招聘中';
                default:
                    return '--';
            }
        },
        levelFilter(val) {
            switch (val) {
                case 1:
                    return '专科';
                case 2:
                    return '本科';
                case 3:
                    return '研究生';
                case 4:
                    return '博士';
                default:
                    return '--';
            }
        },

    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '人力资源'}, {title: '招聘企业列表', path: '/student/recruit-company-list'}, {title: '查看详情'}]);
        this.company_name = this.$route.query.company_name;
        this.filterData.hire_no = this.$route.query.hire_no;
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = {...this.filterData};

            params.page_id = page || this.page.now_page;
            this.$post('/student/work_recruit%5Cget_company_recruit_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: res.msg
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         * @param auth_name
         */
        handleRoute(routeName, query, auth_name) {
            if (auth_name && !this.authResult[auth_name]) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 设置状态前判断
         * @param row
         */
        async beforeSetStatus(row) {
            if(!this.authResult.auth_set_status) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            if(row.status) {
                let reason = await this.$zdPrompt({
                    title: '关闭招聘信息',
                    message: '关闭原因',
                    placeholder: '请输入关闭原因…'
                });

                if(reason) {
                    this.handleSetStatus(row.recruit_no, 0, reason);
                }
            } else {
                this.handleSetStatus(row.recruit_no, 1);
            }
        },

        /**
         * 设置状态请求
         * @param recruit_no
         * @param status
         * @param close_reason
         */
        handleSetStatus(recruit_no, status, close_reason = '') {
            this.$post('/student/work_recruit%5Cset_work_recruit_status', {
                recruit_no,
                status,
                close_reason
            }, res => {
                if (res.code === 1) {
                    this.$notify({
                        title: '提示',
                        type: 'success',
                        message: '操作成功'
                    });
                    this.getTableData();
                } else {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: res.msg
                    });
                }
            });
        }
    }
};
</script>

<style lang="less" scoped>
.page-layout-recruit-company-detail {
    /deep/ .content-wrapper {
        .header {
            .header-left {
                align-items: flex-end;
                .sub-title {
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #2FBDB3;
                }
            }
        }
    }
    .back {
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        cursor: pointer;
    }
}
</style>
